package com.nchu.chatserver.controller;

import com.nchu.chatserver.dao.LoginDTO;
import com.nchu.chatserver.dao.RegisterDTO;
import com.nchu.chatserver.entity.User;
import com.nchu.chatserver.service.AuthService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 王小航
 * @Date: 2025/05/07/22:15
 * @Description:
 */
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/auth")
public class AuthController {
    @Autowired
    private AuthService authService;

    @PostMapping("/register")
    public ResponseEntity<User> register(@RequestBody RegisterDTO registerDTO) {
        return ResponseEntity.ok(authService.register(registerDTO));
    }

    @PostMapping("/login")
    public ResponseEntity<User> login(@RequestBody LoginDTO loginDTO) {

        return ResponseEntity.ok(authService.login(loginDTO));
    }

    @PostMapping("/logout")
    public ResponseEntity<Void> logout(@RequestParam Integer userId) {
        authService.logout(userId);
        return ResponseEntity.ok().build();
    }



}